package main

import "fmt"

func lengthOfNoRepeatingSubStr(s string) int {
	lastOccurred := make(map[byte]int)
	start := 0
	maxLen := 0

	for i, ch := range []byte(s) {
		if lastI, ok := lastOccurred[ch]; ok && (lastI >= start) {
			start = lastI + 1
		}
		if i-start+1 > maxLen {
			maxLen = i - start + 1
		}
		lastOccurred[ch] = i
	}

	return maxLen
}

func main() {
	fmt.Println(lengthOfNoRepeatingSubStr("abcabcbb"))
	fmt.Println(lengthOfNoRepeatingSubStr("akakkwc"))
	fmt.Println(lengthOfNoRepeatingSubStr("b"))
	fmt.Println(lengthOfNoRepeatingSubStr("bbbbb"))
}
